package com.zcsy.manage.web.usualQuestions;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zcsy.commons.constants.Constants;
import com.zcsy.commons.model.RequestConstants;
import com.zcsy.manage.model.base.CellInfo;
import com.zcsy.manage.model.news.HelpManual;
import com.zcsy.manage.service.news.IHelpManualService;

@Controller
@RequestMapping(value = "usualQuestions")
public class UsualQuestionsController {
    
    @Autowired
    IHelpManualService helpManualService;
    
    private final static int repairType = 2;//帮助手册-物业报修类型
    
    /**
     * @description 
     * @param model
     * @return
     * String
     * @author chenxin
     * @date 2016年8月15日下午7:37:26
     */
    @RequestMapping(value = "infoList", method = RequestMethod.GET)
    public String goToRepairUsualQuestionsPage(Integer pNo, Model model,HttpServletRequest request) {
        
        if (pNo == null) {
            pNo = Constants.PAGE_NO;
        }
        
        HelpManual helpManual = new HelpManual();
        String cellId = ((CellInfo) request.getSession().getAttribute(RequestConstants.OWNER_CELL_INFO)).getId();
        helpManual.setCellId(cellId);
        helpManual.setType(repairType);
        // 此处添加PageHelper将会走拦截器，进行分页，分页方法只针对紧跟着PageHelper的查询方法有效
        PageHelper.startPage(pNo, Constants.PAGE_SIZE);
        List<HelpManual> helpManuals = helpManualService.selectByKeyword(helpManual);
        PageInfo<HelpManual> pageInfo = new PageInfo<HelpManual>(helpManuals);
        
        model.addAttribute("helpManuals", pageInfo);
        model.addAttribute("currentPage", pNo);
        
        return "usualQuestions/repairUsualQuestions";
    }
}